//
//  BasicInformationViewController.m
//  MagicZhao
//
//  Created by hy002 on 2017/12/6.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "BasicInformationViewController.h"
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import "GSPickerView.h"
#import "CloseAreaViewController.h"
#import "TypeOfWorkViewController.h"

static NSString *cellPath = @"baseCell";
@interface BasicInformationViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate>
{
    CGFloat scrollViewOffSetY;
    CGFloat remainingDistanceY;
    CGFloat beforeMigrationY;
    UILabel *sexLab;
    UILabel *datesLab;
    UILabel *marryLab;
    UILabel *healthLab;
    UILabel *addressLabel;
    UILabel *workerTypeLab;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *basicinforAry;
@property (nonatomic, strong)UIImage *faceImg;
@property (nonatomic, strong)UIImageView *faceView;
@property (nonatomic, strong)NSString *faceString;
@property (nonatomic, strong)NSString *nameStr;
@property (nonatomic, strong)NSString *phoneStr;
@property (nonatomic, strong)NSString *carNumStr;
@property (nonatomic, strong)NSString *emilStr;
@property (nonatomic, strong)NSString *addressStr;
@property (nonatomic, strong)NSString *shenGaoStr;
@property (nonatomic, strong)NSString *priceStr;
@property (nonatomic, strong)NSString *gardent;
@property (nonatomic, strong)NSString *marry;
@property (nonatomic, strong)NSString *health;
@property (nonatomic, strong)NSString *dateString;
@property (nonatomic, strong)NSString *dateNewStr;
@property (nonatomic, strong)GSPickerView *pickerView;
@property (nonatomic, strong)NSString *areaId;
@property (nonatomic, strong)NSString *siteStr;
@property (nonatomic, strong)NSString *workerYear;
@property (nonatomic, strong)NSString *workerType;
@property (nonatomic, strong)NSString *workerName;

@end

@implementation BasicInformationViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jianpantanchu:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jianpanhuishou:) name:UIKeyboardDidHideNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _faceImg = nil;
    _faceString = _resuModel.photo ? _resuModel.photo : @"";
    _nameStr = _resuModel.linkman ? _resuModel.linkman : @"";
    _phoneStr = _resuModel.phone ? _resuModel.phone : @"";
    _carNumStr = _resuModel.idCardNum ? _resuModel.idCardNum : @"";
    _emilStr = _resuModel.email ? _resuModel.email : @"";
    _addressStr = _resuModel.address ? _resuModel.address : @"";
    _shenGaoStr = _resuModel.height ? _resuModel.height : @"";
    _priceStr = _resuModel.wage ? _resuModel.wage : @"";
    _gardent = _resuModel.sex ? _resuModel.sex : @"0";
    _marry = _resuModel.marry ? _resuModel.marry : @"0";
    _health = _resuModel.health ? _resuModel.health : @"1";
    _dateString = _resuModel.birthDate ? _resuModel.birthDate : @"";
    _dateNewStr = @"";
    _siteStr = [NSString stringWithFormat:@"%@%@%@",_resuModel.user.province ? _resuModel.user.province : @"",_resuModel.user.city ? _resuModel.user.city : @"",_resuModel.user.areaName ? _resuModel.user.areaName : @""];
    _areaId = _resuModel.user.areaId ? _resuModel.user.areaId : @"";
    _workerYear = _resuModel.workingAge ? _resuModel.workingAge : @"";
    _workerType = _resuModel.workID ? _resuModel.workID : @"";
    _workerName = _resuModel.workName ? _resuModel.workName : @"";
    _basicinforAry = @[@"头像",@"姓名",@"性别",@"手机号",@"报价",@"出生年月",@"身份证号",@"电子邮箱",@"现居地区",@"详细地址",@"婚姻状况",@"健康状况",@"身高",@"工龄",@"工种"];
    [self creatUI];
    
}

- (void)creatUI
{
    self.navigationItem.title = @"基本信息";
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.translucent = NO;
    UIButton *rightBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, 40, 30) ImageName:nil Target:self Action:@selector(saveAction) Title:@"保存" Font:16.0];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIBarButtonItem *barbtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = barbtn;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.backgroundColor = BacksColor;
    [_tableview setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    [self.view addSubview:_tableview];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _basicinforAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = _basicinforAry[indexPath.row];
    cell.textLabel.font = NormalFontWithSize(14.0+fontScale);
    cell.textLabel.textColor = RGB(77, 77, 77);
    NSInteger index = indexPath.row;
    if (index == 0)
    {
        UIImageView *faceImgView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-70*displaywidth, 12.5*displaywidth, 50*displaywidth, 50*displaywidth) ImageName:@"toux"];
        if (_faceImg)
        {
            faceImgView.image = _faceImg;
        }
        else
        {
            if (_faceString.length > 0)
            {
                [faceImgView sd_setImageWithURL:[NSURL URLWithString:_faceString] placeholderImage:[UIImage imageNamed:@"toux"]];
            }
            
        }
        faceImgView.contentMode = UIViewContentModeScaleAspectFill;
        faceImgView.layer.masksToBounds = YES;
        [cell.contentView addSubview:faceImgView];
        _faceView = faceImgView;
    }
    NSArray *indexAry = @[@"1",@"3",@"4",@"6",@"7",@"9",@"12",@"13"];
    if ([indexAry containsObject:[NSString stringWithFormat:@"%ld",index]])
    {
        NSString *priceString = [NSString stringWithFormat:@"%@元/小时",_priceStr];
        NSArray *textArray = @[@"",_nameStr,@"",_phoneStr,priceString,@"",_carNumStr,_emilStr,@"",_addressStr,@"",@"",_shenGaoStr,_workerYear];
        UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(100*displaywidth, 5*displaywidth, SCREEN_WIDTH-120*displaywidth, 35*displaywidth) placeholder:@"" passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
        [textfield setValue:RGB(179, 179, 179) forKeyPath:@"_placeholderLabel.textColor"];
        textfield.textColor = RGB(77, 77, 77);
        textfield.textAlignment = NSTextAlignmentRight;
        textfield.text = textArray[index];
        textfield.delegate = self;
        textfield.tag = 100+index;
        [cell.contentView addSubview:textfield];
        if (index == 3 || index == 13 || index == 12)
        {
            textfield.keyboardType = UIKeyboardTypeNumberPad;
            if (index == 13)
            {
                if (![textfield.text containsString:@"年"])
                {
                    textfield.text = [textfield.text stringByAppendingString:@"年"];
                }
                
            }
            if (index == 12)
            {
                if (![textfield.text containsString:@"cm"])
                {
                    textfield.text = [textfield.text stringByAppendingString:@"cm"];
                }
                
            }
        }
        if (index == 4)
        {
            textfield.keyboardType = UIKeyboardTypeDecimalPad;
        }
        
        
    }
    NSArray *indexOtherAry = @[@"2",@"5",@"8",@"10",@"11",@"14"];
    if ([indexOtherAry containsObject:[NSString stringWithFormat:@"%ld",index]])
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UILabel *baseLabel = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 2.5*displayheight, SCREEN_WIDTH-130*displaywidth, 40*displayheight) Font:13.0 Text:@"" Color:RGB(77, 77, 77)];
        baseLabel.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:baseLabel];
        if (index == 2)
        {
            NSArray *sexAry = @[@"保密",@"男",@"女"];
            NSInteger indexRow = [_gardent integerValue];
            NSString *sexType = sexAry[indexRow];
            baseLabel.text = sexType;
            sexLab = baseLabel;
        }
        else if (index == 5)
        {
            baseLabel.text = _dateString;
            datesLab = baseLabel;
        }
        else if (index == 8)
        {
           
            baseLabel.text = _siteStr;
            addressLabel = baseLabel;
        }
        else if (index == 10)
        {
            NSArray *sexAry = @[@"保密",@"已婚",@"未婚"];
            NSInteger indexRow = [_marry integerValue];
            NSString *sexType = sexAry[indexRow];
            baseLabel.text = sexType;
            marryLab = baseLabel;
        }
        else if (index == 11)
        {
            NSArray *sexAry = @[@"较差",@"良好",@"一般"];
            NSInteger indexRow = [_health integerValue];
            NSString *sexType = sexAry[indexRow];
            baseLabel.text = sexType;
            healthLab = baseLabel;
        }
        else if (index == 14)
        {
            baseLabel.text = _workerName;
            workerTypeLab = baseLabel;

        }
    }
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"选择图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        //拍照
        [alertVC addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            HYLog(@"拍照");
            [self takePhoto];
            
        }]];
        
        //从相册中选取
        [alertVC addAction:[UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            HYLog(@"从相册中选取");
            [self choseImageWithTypeCameraTypePhotoLibrary:UIImagePickerControllerSourceTypePhotoLibrary];
            
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            HYLog(@"取消");
            [self dismissViewControllerAnimated:NO completion:nil];
        }]];
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
    else if (indexPath.row == 2)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"选择性别" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _gardent = @"1";
            sexLab.text = @"男";
        }]];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _gardent = @"2";
            sexLab.text = @"女";
            
            
        }]];
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
    else if (indexPath.row == 5)
    {
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; //初始化格式器。
        [formatter setDateFormat:@"YYYY年MM月dd日"];//定义时间为这种格式： YYYY-MM-dd hh:mm:ss 。
        NSString *currentTime = [formatter stringFromDate:[NSDate date]];
        NSString *str = currentTime;
        if ([_dateNewStr containsString:@"年"])
        {
            str = _dateNewStr;
          
        }
        [self.pickerView appearWithTitle:@"年月日" pickerType:GSPickerTypeDatePicker subTitles:nil selectedStr:str sureAction:^(NSInteger path, NSString *pathStr) {
            NSLog(@"%ld   %@",path,pathStr);
            _dateNewStr = pathStr;
            _dateString = [pathStr stringByReplacingOccurrencesOfString:@"年" withString:@"-"];
            _dateString = [_dateString stringByReplacingOccurrencesOfString:@"月" withString:@"-"];
            _dateString = [_dateString stringByReplacingOccurrencesOfString:@"日" withString:@""];
            datesLab.text = _dateString;
        } cancleAction:^{
            
        }];

    }
    else if (indexPath.row == 8)
    {
        WEAKSELF;
        CloseAreaViewController *vc = [[CloseAreaViewController alloc] init];
        vc.chooseOnlyblock = ^(NSString *areaId, NSString *siteStr)
        {
            weakSelf.areaId = areaId;
            weakSelf.siteStr = siteStr;
            addressLabel.text = siteStr;
        };
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 10)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"婚姻状况" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"已婚" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _marry = @"1";
            marryLab.text = @"已婚";
        }]];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"未婚" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _marry = @"2";
            marryLab.text = @"未婚";

            
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"保密" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _marry = @"0";
            sexLab.text = @"保密";
        }]];
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
    else if (indexPath.row == 11)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"健康状况" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"良好" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _health = @"1";
            healthLab.text = @"良好";
        }]];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"一般" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _health = @"2";
            healthLab.text = @"一般";

            
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"较差" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            _health = @"0";
            healthLab.text = @"较差";
        }]];
        
        [self presentViewController:alertVC animated:YES completion:nil];
    }
    else if (indexPath.row == 12)
    {
        
    }
    else if (indexPath.row == 14)
    {
      
        TypeOfWorkViewController *vc = [[TypeOfWorkViewController alloc] init];
        WEAKSELF;
        vc.closeTypeblock = ^(WorkerTypeModel *model)
        {
            weakSelf.workerType = model.ID;
            workerTypeLab.text = model.name;
            weakSelf.workerName = model.name;
        };
        [self.navigationController pushViewController:vc animated:YES];
        

    }
}

- (GSPickerView *)pickerView{
    if (!_pickerView) {
        _pickerView = [[GSPickerView alloc]initWithFrame:self.view.bounds];
    }
    return _pickerView;
}

-(void)takePhoto
{
    //    判断是否打开相机权限
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您尚未开启相机权限，请去系统设置界面打开相机权限！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
        }];
        [alertVC addAction:okAction];
        [self presentViewController:alertVC animated:YES completion:nil];
        
        
    }
    else
    {
        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
        if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            //            设置拍照后的图片可被编辑
            picker.allowsEditing = YES;
            picker.sourceType = sourceType;
            
            [self presentViewController:picker animated:YES completion:nil];
        }else
        {
            
        }
        
    }
}

-(void)choseImageWithTypeCameraTypePhotoLibrary:(UIImagePickerControllerSourceType)type{
    
    UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = type;
    imagePicker.allowsEditing = YES;
    imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:imagePicker animated:YES completion:^{
        
    }];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    //    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {
        UIImageOrientation imageOrientation = image.imageOrientation;
        if(imageOrientation!=UIImageOrientationUp)
        {
            UIGraphicsBeginImageContext(image.size);
            [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
            image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
        }
        
    }
    _faceView.image = image;
    _faceImg = image;
    WEAKSELF;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HttpTool uploadImageWithPath:SERVER_fileUpload params:nil thumbName:@"file" image:image success:^(id json)
     {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([json server_Getcodecheck])
         {
             NSArray *urlAry = json[@"data"];
             if (urlAry.count > 0)
             {
                 NSString *imgurl = urlAry[0];
                 if (imgurl.length > 0)
                 {
                     weakSelf.faceString = imgurl;
                 }
                 
             }
         }
         
     } failure:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     } progress:^(CGFloat progress) {
         
     }];
    
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        return 75*displaywidth;
    }
    return 45*displaywidth;
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.view endEditing:YES];
    return indexPath;
}

// 我们获取当前tableView 的偏移量
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    /* scrollView 的偏移量*/
//    CGFloat offSetY = scrollView.contentOffset.y;
//    scrollViewOffSetY = offSetY;
    
}
// 我们获取那个Cell是被点击的
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    /* 获取当前cell的位置*/
    /* 我们进行层次分析
     * A.superview 则是 cell
     */
    scrollViewOffSetY = _tableview.contentOffset.y;
    CGFloat Hieght = textField.superview.superview.frame.origin.y;
    /* 获取当前点击Cell的位置*/
    CGFloat CurrentCellY = Hieght - scrollViewOffSetY;
    /* 获取剩余高度*/
    CGFloat lastHeight = [UIScreen mainScreen].bounds.size.height - CurrentCellY-200;
    remainingDistanceY = lastHeight;
    
    if (textField.tag == 104)
    {
        if ([textField.text containsString:@"元/小时"])
        {
            textField.text = [textField.text stringByReplacingOccurrencesOfString:@"元/小时" withString:@""];
        }
    }
    if (textField.tag == 112)
    {
        if ([textField.text containsString:@"cm"])
        {
            textField.text = [textField.text stringByReplacingOccurrencesOfString:@"cm" withString:@""];
        }
    }
    if (textField.tag == 113)
    {
        if ([textField.text containsString:@"年"])
        {
            textField.text = [textField.text stringByReplacingOccurrencesOfString:@"年" withString:@""];
        }
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.tag == 104)
    {
        if (![textField.text containsString:@"元/小时"])
        {
            if ([textField.text floatValue] > 0)
            {
                _priceStr = textField.text;
            } else {
                _priceStr = @"";
            }
            textField.text = [textField.text stringByAppendingString:@"元/小时"];
        }
        
    }
    else if (textField.tag == 101)
    {
        _nameStr = textField.text;
    }
    else if (textField.tag == 103)
    {
        _phoneStr = textField.text;
    }
    else if (textField.tag == 106)
    {
        _carNumStr = textField.text;
    }
    else if (textField.tag == 107)
    {
        _emilStr = textField.text;
    }
    else if (textField.tag == 109)
    {
        _addressStr = textField.text;
    }
    else if (textField.tag == 112)
    {
        _shenGaoStr = textField.text;
        textField.text = [textField.text stringByAppendingString:@"cm"];
    }
    else if (textField.tag == 113)
    {
        _workerYear = textField.text;
        textField.text = [textField.text stringByAppendingString:@"年"];
    }
    
}
// 我们在获取弹出键盘的高度和在做计算差值偏移
-(void)jianpantanchu:(NSNotification*)Notification{
    NSLog(@"%@",Notification);
    /* 获取键盘的开始高度*/
    NSDictionary *userInfo = [Notification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat keyBoardStart = keyboardRect.size.height;
    
    //    CGFloat keyBoardStart = [Notification.userInfo[@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue].size.height;
    if (remainingDistanceY < keyBoardStart) {
        /* 获取差值*/
        CGFloat differenceValue = keyBoardStart -remainingDistanceY;
        beforeMigrationY = differenceValue;
        [_tableview setContentOffset:CGPointMake(0, differenceValue + scrollViewOffSetY) animated:YES];
    }
}

// 我们为了防止tableView不能返回原始没有被点击的位置(这是防止用户在键盘弹出的时候，在滑动而造成的混乱)
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    /* 防止错乱停止编辑*/
    [self.view endEditing:YES];
}
// 最后键盘隐藏，返回点击前的偏移
-(void)jianpanhuishou:(NSNotification*)Notification{
    NSLog(@"Hide");
    [_tableview setContentOffset:CGPointMake(0, scrollViewOffSetY) animated:YES];
    beforeMigrationY = 0.0;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

//保存
- (void)saveAction
{
    [self.view endEditing:YES];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    [dic setObject:_gardent forKey:@"sex"];
    [dic setObject:_marry forKey:@"marry"];
    [dic setObject:healthLab.text forKey:@"health"];
    if (![_faceString isEqualToString:@""])
    {
        [dic setObject:_faceString forKey:@"photo"];
    } else {
        [dic setObject:@"" forKey:@"photo"];
    }
    if (![_nameStr isEqualToString:@""])
    {
        [dic setObject:_nameStr forKey:@"linkman"];
    } else {
        [dic setObject:@"" forKey:@"linkman"];
    }
    if (![_phoneStr isEqualToString:@""])
    {
        [dic setObject:_phoneStr forKey:@"phone"];
    } else {
        [dic setObject:@"" forKey:@"phone"];
    }
    if ([_priceStr isEqual:@""]) {
        [LTools showMBProgressWithText:@"报价不能为空" addToView:self.view];
        return;
    }
    if ([_priceStr floatValue] > 0)
    {
        [dic setObject:_priceStr forKey:@"wage"];
    } else {
        [dic setObject:@"" forKey:@"wage"];
    }
    if (![_dateString isEqualToString:@""])
    {
        [dic setObject:_dateString forKey:@"birthDate"];
    } else {
        [dic setObject:@"" forKey:@"birthDate"];
    }
    if (![_carNumStr isEqualToString:@""])
    {
        [dic setObject:_carNumStr forKey:@"idCardNum"];
    } else {
        [dic setObject:@"" forKey:@"idCardNum"];
    }
    if (![_emilStr isEqualToString:@""])
    {
        [dic setObject:_emilStr forKey:@"email"];
    } else {
        [dic setObject:@"" forKey:@"email"];
    }
    if (![_areaId isEqualToString:@""])
    {
        NSDictionary *areaDic = @{@"area":@{@"id":_areaId}};
        [dic setObject:areaDic forKey:@"user"];
    } else {
//        [dic setObject:@"" forKey:@"user"];
    }
    if (![_addressStr isEqualToString:@""])
    {
        [dic setObject:_addressStr forKey:@"address"];
    } else {
        [dic setObject:@"" forKey:@"address"];
    }
    if ([_shenGaoStr containsString:@"."]) {
        [LTools showMBProgressWithText:@"身高不能输入小数" addToView:self.view];
        return;
    }
    if (![_shenGaoStr isEqualToString:@""])
    {
        [dic setObject:_shenGaoStr forKey:@"height"];
    } else {
        [dic setValue:@(-1) forKey:@"height"];
    }
    if (![_workerYear isEqualToString:@""])
    {
        [dic setObject:_workerYear forKey:@"workingAge"];
    } else {
        [dic setObject:@(-1) forKey:@"workingAge"];
    }
    if ([_workerType integerValue] > 0)
    {
        [dic setObject:@{@"id":[NSString stringWithFormat:@"%@",_workerType]} forKey:@"work"];
    }
    
    [self requestUpdateWorkerInfo:dic];
    
}

- (void)requestUpdateWorkerInfo:(NSDictionary *)dic
{
    WEAKSELF;
    [HYBaseHandler requestUpdateWorkerInfoParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            [LTools showMBProgressWithText:@"保存成功" addToView:sharedDelegate.window];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
